package com.android.killtencent.task;

import android.app.Activity;
import android.os.AsyncTask;

import com.android.killtencent.BaseApp;
import com.android.killtencent.connection.XmppConnectionHelper;

/**
 * 作者:	Rose
 * 业务名:    注册线程类
 * 功能说明:  启动异步进行用户注册
 * 编写日期:    2015-02-10
 */
public class RegisterTask extends AsyncTask<Void, Void, Integer> {
    private String userName;
    private String passWord;
    private Activity activity;

    public RegisterTask(String userName, String passWord, Activity activity) {
        this.userName = userName;
        this.passWord = passWord;
        this.activity = activity;
    }

    @Override
    protected Integer doInBackground(Void... params) {
        int state = XmppConnectionHelper.getInstance().registerUser(userName, passWord);
        return state;
    }

    @Override
    protected void onPostExecute(Integer integer) {
        super.onPostExecute(integer);
        switch (integer) {
            case 1:
                BaseApp.getInstance().showToast("注册成功");
                //注册成功后即同时进行自动登陆处理
                new LoginTask(userName , passWord ,activity).execute();
                break;
            case 2:
                BaseApp.getInstance().showToast("这个账号已经存在");
                break;
        }
    }
}
